<template>
  <div>
    <div class="header">
      <el-button type="primary" @click="back" icon="el-icon-arrow-left">返回</el-button>
      <p>修改手机</p>
      <span class="line"></span>
    </div>
    <section>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <div class="first">
          <el-form-item label="新手机号:" prop="new">
            <el-input v-model="ruleForm.new"></el-input>
            <el-button :plain="true" type="primary" @click="get">获取验证码</el-button>
          </el-form-item>
        </div>


        <el-form-item label="验证码:" prop="pass">
          <el-input v-model="ruleForm.pass"></el-input>
        </el-form-item>


        <el-form-item>
          <el-button :plain="true" type="primary" @click="submitForm('ruleForm')">保存</el-button>
        </el-form-item>
      </el-form>
    </section>

  </div>
</template>

<script>
export default {
  name: '',
  components: {},
  data() {
    var checkNew = (rule, value, callback) => {
      if (value === '') {
        return callback(new Error('新手机号不能为空'));
      }
      callback();
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        return callback(new Error('验证码不能为空'));
      }
      callback();
    };

    return {
      ruleForm: {
        new: '',
        pass: '',
        arr: [1, 2, 3, 4]
      },
      rules: {
        new: [
          { validator: checkNew, trigger: 'blur' }
        ],
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    array() {
      let a = this.arr.some(e => { return e === 5 })
      if (a) {
        console.log("5");
      } else {
        console.log("6666");
      }
    },
    back() {
      this.$router.push("/set/security")
      this.array()
    },
    get() {
      console.log("发送验证码成功");
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message({
            message: '保存成功',
            type: 'success',
            duration: '1000',
          });
          this.$router.push("/set/security")
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style scoped lang='less'>
.header {
  position: relative;
  font-size: 28px;
  text-align: center;

  color: rgb(102, 102, 102);

  .el-button {
    padding-left: 12px;
    position: absolute;
    margin-left: -50%;
    background-color: rgb(225, 152, 163);
    border-color: rgb(109, 71, 71);
    color: rgb(236, 220, 220);
  }

  .line {
    display: block;
    width: 100%;
    height: 2px;
    background-color: silver;
    position: absolute;
    left: 0px;
    top: 50px;
  }
}

section {
  text-align: center;
  position: relative;
  margin-left: 25%;
  margin-top: 80px;
  width: 400px;

  .first {
    .el-button {
      position: absolute;
      margin-left: 20px;
    }
  }
}
</style>